package com.alumni_circle.mapper.me;

import com.alumni_circle.core.entity.rbac.response.UserEntity;
import com.alumni_circle.entity.me.User;
import com.alumni_circle.entity.me.VO.UserSearchVO;
import com.alumni_circle.entity.me.VO.UserUpdateVO;
import com.alumni_circle.entity.me.VO.UserViewVO;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.List;

/**
 * @author 龙小虬
 * @since 2020-07-06 22:11
 */

public interface UserMapper extends BaseMapper<User> {

    @Select("SELECT user.id,user.username,user.`name`,user.update_by,user.update_time,user.phone,user.email,user.club,user.professional,user.state,role.role_name as role\n" +
            "FROM user,user_role,role\n" +
            "WHERE (user.name like concat('%',#{name},'%')) AND (user.update_by like concat('%',#{updateBy},'%')) AND (user.update_time like concat('%',#{updateTime},'%')) AND (user.email like concat('%',#{email},'%')) AND (user.phone like concat('%',#{phone},'%')) AND (role.role_name like concat('%',#{role},'%'))\n" +
            "AND user.id = user_role.user_id AND user_role.role_id = role.id")
    List<UserUpdateVO>searchUser(@Param("name")String name,@Param("updateBy")String updateBy,@Param("updateTime")String updateTime,@Param("email")String email,@Param("phone")String phone,@Param("role")String role);

    @Select("SELECT user.username,user.password,user.id,user.name,user.icon,user.update_time,user.create_time,user.email,user.club,user.phone,role.role_name as role\n" +
            "FROM user,user_role,role\n" +
            "WHERE user.id = user_role.user_id AND user_role.role_id = role.id AND user.username = #{username}")
    User getUserInfo(@Param("username")String username);

    @Select("SELECT user.id,user.username,user.`name`,user.update_by,user.update_time,user.phone,user.email,user.club,user.professional,user.state,role.role_name as role\n" +
            "FROM user,user_role,role\n" +
            "WHERE user.id = user_role.user_id AND user_role.role_id = role.id")
    List<UserUpdateVO> getAllUsers();

    @Select("update user " +
            "set user.state = #{state} " +
            "where id = #{id}")
    void updateUser(@Param("state")String state,@Param("id")String id);

    @Select("DELETE FROM user\n" +
            "WHERE id = #{id}")
    void delUser(@Param("id")String id);
}
